/*   1:    */ package tt.dz.web.controller.user;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.text.SimpleDateFormat;
/*   5:    */ import java.util.ArrayList;
/*   6:    */ import java.util.LinkedHashMap;
/*   7:    */ import java.util.List;
/*   8:    */ import javax.annotation.Resource;
/*   9:    */ import javax.servlet.http.HttpServletRequest;
/*  10:    */ import javax.servlet.http.HttpServletResponse;
/*  11:    */ import org.apache.commons.lang3.StringUtils;
/*  12:    */ import org.springframework.beans.factory.annotation.Autowired;
/*  13:    */ import org.springframework.beans.factory.annotation.Qualifier;
/*  14:    */ import org.springframework.stereotype.Controller;
/*  15:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  16:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  17:    */ import tt.dz.biz.service.cardno.CardNoBuilder;
/*  18:    */ import tt.dz.biz.service.cardno.CardNoDirector;
/*  19:    */ import tt.dz.biz.service.cardno.CardNoProduct;
/*  20:    */ import tt.dz.biz.service.cardno.DefaulCardNoDirector;
/*  21:    */ import tt.dz.biz.service.cardno.DefaultCardNoBuilder;
/*  22:    */ import tt.dz.biz.service.cardno.DefaultCardNoCardConfigSequenceGenerator;
/*  23:    */ import tt.dz.biz.service.financial.MerchantService;
/*  24:    */ import tt.dz.biz.service.user.OfflineAccountService;
/*  25:    */ import tt.dz.common.BusinessException;
/*  26:    */ import tt.dz.common.DateUtil;
import tt.dz.common.DzConstants;
/*  27:    */ import tt.dz.common.DzConstants.CardBIN;
/*  28:    */ import tt.dz.common.DzConstants.CardType;
/*  29:    */ import tt.dz.common.ExcelUtill;
/*  30:    */ import tt.dz.common.LogUtil;
/*  31:    */ import tt.dz.vo.MerchantVO;
/*  32:    */ import tt.dz.vo.OfflineAccountVO;
/*  33:    */ import tt.dz.vo.ResponseModle;
/*  34:    */ import tt.dz.web.controller.BaseController;
/*  35:    */ 
/*  36:    */ @Controller
/*  37:    */ public class OfflineAccountController
/*  38:    */   extends BaseController
/*  39:    */ {
/*  40:    */   @Resource(name="offlineAccountService")
/*  41:    */   private OfflineAccountService offlineAccountService;
/*  42:    */   @Autowired
/*  43:    */   @Qualifier("merchantService")
/*  44:    */   private MerchantService merchantService;
/*  45:    */   
/*  46:    */   @RequestMapping(value={"/batchCreateOfflineAccount"}, produces={"application/json;charset=UTF-8"})
/*  47:    */   @ResponseBody
/*  48:    */   public String batchCreateOfflineAccount(HttpServletRequest request, HttpServletResponse response)
/*  49:    */   {
/*  50: 45 */     Object result = null;
/*  51:    */     
/*  52: 47 */     int createdAmountSuccess = 0;
/*  53:    */     try
/*  54:    */     {
/*  55: 49 */       String merchantCode = request.getParameter("merchantCode");
/*  56: 50 */       MerchantVO merchantVO = this.merchantService.queryMerchantByCode(merchantCode);
/*  57: 51 */       String areaCode = request.getParameter("areaCode");
/*  58: 52 */       areaCode = StringUtils.isBlank(areaCode) ? "0028" : areaCode.trim();
/*  59: 53 */       Integer createAmount = Integer.valueOf(Integer.parseInt(request.getParameter("createAmount")));
/*  60: 54 */       boolean excuteFlag = false;
/*  61: 55 */       SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
/*  62: 56 */       String batNo = format.format(DateUtil.getDBCurrentTime());
/*  63:    */       
/*  64: 58 */       DzConstants.CardType cardType = DzConstants.CardType.OFFLINE_CARD;
/*  65: 59 */       DzConstants.CardBIN cardBIN = DzConstants.CardBIN.CARDBIN_188;
/*  66: 60 */       CardNoBuilder cardNoBuilder = new DefaultCardNoBuilder();
/*  67: 61 */       DefaultCardNoCardConfigSequenceGenerator cardNoSequenceGenerator = new DefaultCardNoCardConfigSequenceGenerator();
/*  68: 62 */       cardNoSequenceGenerator.setCardType(cardType);
/*  69: 63 */       cardNoSequenceGenerator.setCardBin(cardBIN);
/*  70: 64 */       cardNoSequenceGenerator.setMerchant(merchantVO);
/*  71: 65 */       cardNoSequenceGenerator.setAreaCode(areaCode);
/*  72: 66 */       CardNoDirector director = new DefaulCardNoDirector(cardType.value(), cardBIN.value(), merchantCode, areaCode, cardNoSequenceGenerator);
/*  73: 67 */       director.setBuilder(cardNoBuilder);
/*  74: 68 */       CardNoProduct[] cardNoProducts = director.product(createAmount.intValue());
/*  75: 69 */       OfflineAccountVO offlineAccountVO = null;
/*  76: 70 */       for (CardNoProduct cardNoProduct : cardNoProducts)
/*  77:    */       {
/*  78: 71 */         offlineAccountVO = this.offlineAccountService.generateOfflineAccount(cardNoProduct, batNo);
/*  79: 72 */         excuteFlag = this.offlineAccountService.insertOfflineAccount(offlineAccountVO);
/*  80: 73 */         createdAmountSuccess += (excuteFlag ? 1 : 0);
/*  81:    */       }
/*  82: 75 */       result = Integer.valueOf(createdAmountSuccess);
/*  83:    */     }
/*  84:    */     catch (BusinessException e)
/*  85:    */     {
/*  86: 77 */       LogUtil.error("批量建立离线现金卡出现异常", e);
/*  87: 78 */       result = e.getStatusDescribe();
/*  88:    */     }
/*  89:    */     catch (Exception e)
/*  90:    */     {
/*  91: 80 */       LogUtil.error("批量建立离线现金卡出现异常", e);
/*  92:    */     }
/*  93: 82 */     return JSON.toJSONString(assemblyResponseData(true, result));
/*  94:    */   }
/*  95:    */   
/*  96:    */   @RequestMapping(value={"/listAllOfflineAccount"}, produces={"application/json;charset=UTF-8"})
/*  97:    */   @ResponseBody
/*  98:    */   public String listAllOfflineAccount()
/*  99:    */   {
/* 100: 92 */     ResponseModle responseModle = null;
/* 101:    */     try
/* 102:    */     {
/* 103: 94 */       List<OfflineAccountVO> offlineAccountList = this.offlineAccountService.listAllOfflineAccount();
/* 104: 95 */       responseModle = new ResponseModle("success", offlineAccountList);
/* 105:    */     }
/* 106:    */     catch (Exception e)
/* 107:    */     {
/* 108: 97 */       LogUtil.error("查询所有离线现金卡异常", e);
/* 109: 98 */       responseModle = new ResponseModle("error", new ArrayList());
/* 110:    */     }
/* 111:100 */     return JSON.toJSONString(responseModle);
/* 112:    */   }
/* 113:    */   
/* 114:    */   @RequestMapping(value={"/batchUpdateOfflineAccount"}, produces={"application/json;charset=UTF-8"})
/* 115:    */   @ResponseBody
/* 116:    */   public String batchUpdateOfflineAccount(HttpServletRequest request)
/* 117:    */   {
/* 118:111 */     boolean excuteFlag = false;
/* 119:    */     try
/* 120:    */     {
/* 121:113 */       List<OfflineAccountVO> offlineAccountList = JSON.parseArray(request.getParameter("modifyList"), OfflineAccountVO.class);
/* 122:    */       
/* 123:115 */       excuteFlag = this.offlineAccountService.bacthUpdateOfflineAccount(offlineAccountList);
/* 124:    */     }
/* 125:    */     catch (Exception e)
/* 126:    */     {
/* 127:118 */       LogUtil.error(" 批量更新离线现金卡对象异常", e);
/* 128:    */     }
/* 129:120 */     return JSON.toJSONString(assemblyResponseData(excuteFlag, null));
/* 130:    */   }
/* 131:    */   
/* 132:    */   @RequestMapping({"/exportOfflineAccount "})
/* 133:    */   @ResponseBody
/* 134:    */   public byte[] exportOfflineAccount(HttpServletRequest request, HttpServletResponse response)
/* 135:    */   {
/* 136:132 */     byte[] b = null;
/* 137:    */     try
/* 138:    */     {
/* 139:134 */       OfflineAccountVO offlineAccountVO = (OfflineAccountVO)JSON.parseObject(request.getParameter("offlineAccountVO"), OfflineAccountVO.class);
/* 140:    */       
/* 141:136 */       List<OfflineAccountVO> offlineAccountList = this.offlineAccountService.queryOfflineAccountAndConvert(offlineAccountVO);
/* 142:137 */       LinkedHashMap<String, String> fieldMap = new LinkedHashMap();
/* 143:138 */       fieldMap.put("卡号", "cardNo");
/* 144:139 */       fieldMap.put("状态", "stateDesc");
/* 145:140 */       fieldMap.put("余额", "acctBal");
/* 146:141 */       fieldMap.put("初始化日期", "initDate");
/* 147:    */       
/* 148:143 */       b = ExcelUtill.getCSVByteArray("离线现金卡报表", fieldMap, offlineAccountList);
/* 149:    */       
/* 150:145 */       response.setHeader("Content-Disposition", "attachment;fileName=demo.csv");
/* 151:146 */       response.setHeader("Content-Transfer-Encoding", "binary");
/* 152:147 */       response.setContentType("application/vnd.ms-excel; charset=utf-8");
/* 153:    */     }
/* 154:    */     catch (Exception e)
/* 155:    */     {
/* 156:149 */       LogUtil.error("根据传入条件查询离线现金卡并导出excel异常", e);
/* 157:    */     }
/* 158:151 */     return b;
/* 159:    */   }
/* 160:    */   
/* 161:    */   @RequestMapping(value={"/queryOfflineAccount"}, produces={"application/json;charset=UTF-8"})
/* 162:    */   @ResponseBody
/* 163:    */   public String queryOfflineAccount(HttpServletRequest request)
/* 164:    */   {
/* 165:162 */     ResponseModle responseModle = null;
/* 166:    */     try
/* 167:    */     {
/* 168:164 */       OfflineAccountVO offlineAccountVO = (OfflineAccountVO)JSON.parseObject(request.getParameter("offlineAccountVO"), OfflineAccountVO.class);
/* 169:    */       
/* 170:166 */       List<OfflineAccountVO> offlineAccountList = this.offlineAccountService.queryOfflineAccount(offlineAccountVO);
/* 171:167 */       responseModle = new ResponseModle("success", offlineAccountList);
/* 172:    */     }
/* 173:    */     catch (Exception e)
/* 174:    */     {
/* 175:169 */       LogUtil.error("根据传入条件查询离线现金卡并导出excel异常", e);
/* 176:170 */       responseModle = new ResponseModle("error", new ArrayList());
/* 177:    */     }
/* 178:172 */     return JSON.toJSONString(responseModle);
/* 179:    */   }
/* 180:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.user.OfflineAccountController
 * JD-Core Version:    0.7.0.1
 */